#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/11/21 1:31 PM
import hashlib
from typing import Optional


def dict2tuple(prefix: Optional[str], data: dict):
    res = []
    if prefix:
        prefix = prefix + '.'
    else:
        prefix = ""
    for k, v in data.items():
        if not isinstance(v, dict):
            res.append(
                (f"{prefix}{k}", str(v))
            )
        else:
            res.extend(
                dict2tuple(f"{prefix}{k}", v)
            )
    return res


def md5_hash(string):
    md5 = hashlib.md5()
    md5.update(str(string).encode())
    return md5.hexdigest()
